﻿CREATE VIEW dbo.v_Upload_10
AS
SELECT     U.ID, U.UploadInfoID, UI.Date AS UploadDate, dbo.PmtsAdjMos(U.[# of Payments], U.[Pmt Freq], 1) AS NumberOfPaymentsM, U.[# of Payments], 
                      ISNULL(U.[# Pmts Md], dbo.PaymentMadeByPrincipalBalance(U.[Amt Financed], U.[Payment Amount], U.[Open Date], U.[1st# Payment Date], 
                      U.[# of Payments], U.[Pmt Freq], U.APR, 3, U.[Principal Balance])) AS [# Pmts Md], U.[# Pmts Remaining], U.[Customer #], 
                      dbo.DefaultString(U.[Last Name], ISNULL(U.[Last Name], dbo.clr_RegEx_MatchGroup(U.[Full Name], N'^\s*([^\s,]+)', 1))) AS [Last Name], 
                      dbo.DefaultString(U.[First Name], ISNULL(U.[First Name], dbo.clr_RegEx_MatchGroup(U.[Full Name], N'^\s*[^\s,]+[\s,]*(.+?)\s*$', 1))) AS [First Name], 
                      U.[Full Name], U.Address, U.City, U.St, U.[Zip Code], U.[Home Phone #], U.[Work Phone #], U.[Car Year], dbo.ModelAge(U.[Car Year], UI.Date) 
                      AS ModelAge, CASE WHEN ISNUMERIC(Mileage) = 1 THEN (CASE WHEN Mileage > 30000 THEN Mileage ELSE dbo.ModelAge([Car Year], Date) 
                      * 12000 END) ELSE 0 END AS Mileage, U.Make, U.Model, U.Serial#, U.[Pmt Freq], U.[Total $ Paid], U.[Open Date], U.[Maturity Date], 
                      U.[Pymnt Schedule], U.[Payment Amount], U.[Total Payments], U.[1st# Payment Date], U.[Last Payment Date], U.[Next Payment Date], 
                      U.[Balance Remaining], U.[Total Sales Price], U.[Finance Charges], U.[Purchase Price], U.[Other Chgs Balance], U.P#O#E#, U.[Loan#/Comments], 
                      U.[Primary SSN], U.[Amt Financed], U.[Principal Balance], U.[Interest Accrued], U.APR, U.[Recourse Y/N?], U.[Black Book Value (Avg)], 
                      U.[Down Payment], U.[Joint Name], U.[Joint Address], U.[Joint City], U.[Joint State], U.[Joint Zipcode], U.[Joint SSN], U.[Joint H Phone#], 
                      U.[Joint W Phone#], U.[Primary Cell #], U.LoanID, U.ProcessingError, U.BookValue, U.BookValueTypeID, CBP_VT.TypeID AS BookProviderValueTypeID, 
                      CBP_VT.TypeName AS BookProviderValueTypeName, CBP.Code AS BookProviderCode, U.VinCheck, U.InterestTypeID, IT.Name AS InterestTypeName, 
                      IT.Code AS InterestTypeCode, CONVERT(int, U.[Principal Balance] / NULLIF (U.BookValue, 0) * 100) AS LTV, UD.Tier, UD.Recourse, 
                      UD.ProgramID AS DecisionProgramID, UD.Price AS DecisionPrice, UD.Program AS DecisionProgram
FROM         dbo.t_UploadInfo AS UI INNER JOIN
                      dbo.t_Upload AS U ON UI.ID = U.UploadInfoID LEFT OUTER JOIN
                      dbo.v_UploadDecision AS UD ON U.ID = UD.UploadID LEFT OUTER JOIN
                      dbo.ts_InterestType AS IT ON U.InterestTypeID = IT.ID LEFT OUTER JOIN
                      dbo.ts_CarBookProvider AS CBP INNER JOIN
                      dbo.ts_CarBookProvider_ValueType AS CBP_VT ON CBP.ID = CBP_VT.ProviderID ON U.BookValueTypeID = CBP_VT.ID

GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane1', @value = N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1[35] 4[49] 3) )"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4[30] 2[40] 3) )"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4[50] 3) )"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1[75] 4) )"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4[60] 2) )"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4) )"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "UI"
            Begin Extent = 
               Top = 224
               Left = 484
               Bottom = 332
               Right = 648
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "U"
            Begin Extent = 
               Top = 6
               Left = 227
               Bottom = 412
               Right = 416
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "UD"
            Begin Extent = 
               Top = 6
               Left = 454
               Bottom = 141
               Right = 605
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "IT"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 99
               Right = 189
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "CBP"
            Begin Extent = 
               Top = 316
               Left = 667
               Bottom = 409
               Right = 818
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "CBP_VT"
            Begin Extent = 
               Top = 399
               Left = 495
               Bottom = 507
               Right = 646
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 80
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         W', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_Upload_10';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane2', @value = N'idth = 1500
         Width = 1755
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1590
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 12705
         Alias = 1755
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_Upload_10';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPaneCount', @value = 2, @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_Upload_10';

